//
//  DecisionMakerListViewController.m
//
//
//  Created by mac on 15/1/11.
//  Copyright (c) 2015年 mac. All rights reserved.
//

#import "SiftView.h"
#import "ZuZhiViewController.h"
#import "DecisionMakerListViewController.h"
#import "DecisionMakerListCell.h"
#import "ProductPlanViewController.h"
#import "LPCTool.h"
#import "LPCAppColor.h"
#import "Masonry.h"

@interface DecisionMakerListViewController ()
@property (weak, nonatomic) IBOutlet UITextField *textField;

@property (weak, nonatomic) IBOutlet UIButton *calendarButton;
/** calendarView */
@property (weak, nonatomic) UIView * calendarView;

/** buttons */
@property(weak, nonatomic) NSMutableArray<UIButton *> * buttons;
@end

@implementation DecisionMakerListViewController
- (IBAction)siftButtonClicked:(UIButton *)sender {

    NSLog(@"%@ | %s",self.class,__func__);
    
//    ZuZhiViewController *viewController = [[ZuZhiViewController alloc] init];
//    
//    [self.navigationController pushViewController:viewController animated:YES];
    //sn_note:=========  ============================ stone 🐳 ===========/
    /** 蒙版 */
    UIView * bgView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    bgView.backgroundColor = [UIColor blackColor];
    bgView.alpha = 0.0;
    [self.navigationController.view addSubview:bgView];
    //sn_note:=========  ============================ stone 🐳 ===========/
    
    SiftView * siftView =  [SiftView view];
    siftView.bgView = bgView;
    CGFloat w = 338 / 375.0 * [UIScreen mainScreen].bounds.size.width;
    siftView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width, 0, w, [UIScreen mainScreen].bounds.size.height);
    
    [self.navigationController.view addSubview:siftView];
    
    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        bgView.alpha = 0.7;
        //
        CGFloat w = 338 / 375.0 * [UIScreen mainScreen].bounds.size.width;
        siftView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - w, 0, w, [UIScreen mainScreen].bounds.size.height);
    } completion:^(BOOL finished) {
        //
    }];
}

- (IBAction)calendarButtonClicked:(UIButton *)sender {
    NSLog(@"%@ | %s",self.class,__func__);
    
    sender.selected = !sender.selected;
    
    if (sender.selected) {
        self.calendarView.hidden = NO;
    }else{
        self.calendarView.hidden = YES;
    }
    
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        self.dataList = [[NSMutableArray alloc] initWithCapacity:10];
        //        self.sectionNameList = [[NSMutableArray alloc] initWithCapacity:10];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.title = @"种植决策人清单";
    
    self.textField.returnKeyType = UIReturnKeyGoogle;
    
    [self initViews];
    [self registerNib];
    
    //sn_note:=========  ============================ stone 🐳 ===========/
    UIImageView * calendarView = ({
        UIImageView * imageView = [[UIImageView alloc] init];
        imageView.userInteractionEnabled = YES;
//        imageView.backgroundColor = [UIColor orangeColor];
        imageView.layer.masksToBounds = YES;
        imageView.image = [UIImage imageNamed:@"01-year-select"];
        
        [self.view addSubview:imageView];
        
        
        [imageView mas_makeConstraints:^(MASConstraintMaker * make) {
            make.left.mas_equalTo(self.calendarButton.mas_left).offset(-10);
            make.right.mas_equalTo(self.textField.mas_left).offset(0);
            make.top.mas_equalTo(self.calendarButton.mas_bottom).offset(0);
            
            make.height.mas_equalTo(44*3);
        }];
        
    
        imageView;
    });
    self.calendarView = calendarView;
    calendarView.hidden = YES;
    
    NSArray * titles = @[@"2014年度生产计划",@"2015年度生产计划",@"2016年度生产计划"];
    self.buttons = @[].mutableCopy;
    for(int i = 0; i < titles.count; i++) {
        UIButton * button = [[UIButton alloc] init];
        button.tag = i;
        [button setTitle:titles[i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        button.titleLabel.font = [UIFont systemFontOfSize:15];
        
        [button addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];

        [self.calendarView addSubview:button];
        
        [self.buttons addObject:button];
        [button mas_makeConstraints:^(MASConstraintMaker * make) {
            make.left.mas_equalTo(self.calendarView.mas_left).offset(0);
            make.right.mas_equalTo(self.calendarView.mas_right).offset(0);
            make.top.mas_equalTo(self.calendarView.mas_top).offset(10+i*35);
            
            make.height.mas_equalTo(35);
        }];
        
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = HexRGB(0xdddddd);
        [self.calendarView addSubview:view];
        
        
        [view mas_makeConstraints:^(MASConstraintMaker * make) {
            make.left.mas_equalTo(button.mas_left).offset(12);
            make.right.mas_equalTo(button.mas_right).offset(-12);
            make.top.mas_equalTo(button.mas_bottom).offset(0);
            
            make.height.mas_equalTo(1);
        }];
        
        if (i== titles.count - 1) {
            [view removeFromSuperview];
        }
    }

    
    


}
-(void)btnClicked : (UIButton *)sender {
    NSLog(@"%s", __func__);
    
    NSLog(@"sender = %@",@(sender.tag));
    
    
}

- (void)initViews
{
    self.tblData.dataSource = self;
    self.tblData.delegate = self;

    [[[self viewTop] layer] setCornerRadius:8.0f];
    [[[self viewTop] layer] setBorderWidth:0.5f];
    [[[self viewTop] layer] setBorderColor:[[LPCTool colorWithHexString:COLOR_APP_BG] CGColor]];
}

- (void)registerNib
{
    UINib *nib = [UINib nibWithNibName:@"DecisionMakerListCell" bundle:nil];
    [self.tblData registerNib:nib forCellReuseIdentifier:@"DecisionMakerListCell"];
}

#pragma mark 排序 当移动了某一行时候会调用

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 116;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [cell setBackgroundColor:[UIColor clearColor]];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    //    return self.dataList.count;
    return 5;
}

//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 78; }

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DecisionMakerListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DecisionMakerListCell"];
    //    DecisionMakerListBean *elem = [self.dataList objectAtIndex:indexPath.row];

    //    cell.btnFavourite.selected = (elem.favouriteFlag == 1);
    //    cell.btnFavourite.tag = indexPath.row;
    //    [cell.btnFavourite addTarget:self action:@selector(doFavourite:) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}

//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
//{
//    return 32;
//}
//
//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
//{
//    UIView *view;
//    view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 32)];
//    view.backgroundColor = [LPCTool colorWithHexString:COLOR_BUTTON_MAIN_N];
//    UILabel *label;
//    label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, tableView.frame.size.width - 10, 32)];
//    label.font = [UIFont boldSystemFontOfSize:16.0];
//    label.text = self.sectionNameList[section];
//    [view addSubview:label];
//    return view;
//}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    /**  ZX011	联社	生产计划	种植决策人清单	bug	头像	头像应该是不能点击的，目前可以点击进入生产计划清单页面	4		2016/11/15		 */
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    //    DecisionMakerListBean *elem = [self.dataList objectAtIndex:indexPath.row];
    ProductPlanViewController *viewController = [[ProductPlanViewController alloc] initWithNibName:@"ProductPlanViewController" bundle:nil];
    [self.navigationController pushViewController:viewController animated:YES];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
